/*
 * Copyright (C) RT, 2017 by kiterunner_t
 * TO THE HAPPY FEW
 */

package com.zgys.mes.common.config;

import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.zgys.mes.util.gson.ValuedEnumAdapter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class BeanConfig {
//    @Bean
//    public TimerScheduler createTimerScheduler() {
//        return new TimerScheduler();
//    }

    @Bean
    public Gson createGson() {
        Class[] registerCls = {
//                ToolReportMode.class,
//                ToolStatus.class,
//                ToolType.class
        };

        GsonBuilder builder = new GsonBuilder();
        for (Class cls : registerCls) {
            builder.registerTypeAdapter(cls, new ValuedEnumAdapter<>(cls));
        }

        Gson g = builder.setDateFormat("yyyy-MM-dd hh:mm:ss")
                .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
                .create();

        return g;
    }
}

